package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.User;
import com.indusfo.spc.service.UserService;
import com.indusfo.spc.untlis.GsonUtil;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 类说明:
 *
 * @author Hewb
 *
 * @version 创建时间：2018年12月6日 上午11:12:58
 */
@Controller
public class LoginController {
    /**
     * 用户登陆接口
     *
     * @Title: LoginController
     * @param user
     * @return
     */

    @Resource
    private UserService userService;


    @RequestMapping("/service/doLogin")
    @ResponseBody
    public JSONObject login(User user, HttpServletRequest request) {
        JSONObject json =  userService.loginUser(user);
//        System.out.println(user.getUserId());
        request.getSession().setAttribute("user", json.getData());

        return  json;
    }

    /**
     * 退出当前用户
     *
     * @Title: LoginController
     * @param session
     * @return
     */
    @RequestMapping("/service/logOut")
    @ResponseBody
    public JSONObject loginout(HttpSession session) {
        return JSONObject.oK();
    }

    @RequestMapping("/service/treeMenu")
    @ResponseBody
    public JSONObject treeMenu(Integer userId) {
        JSONObject json =  userService.treeMenu(userId);
        return  json;
    }

    /**
     * @Method arrayRole
     * @Author 熊冰
     * @Version  1.0
     * @Description
     * @param lRoleId
     * @Return com.indusfo.spc.vo.JSONObject
     * @Exception 角色  权限数组
     * @Date 2019/9/2 8:58
     */
    @RequestMapping("/service/arrayRole")
    @ResponseBody
    public JSONObject arrayRole(Integer lRoleId) {
        JSONObject json =  userService.arrayRole(lRoleId);

        return  json;
    }
    @RequestMapping("/service/arrayMenu")
    @ResponseBody
    public JSONObject arrayMenu(Integer userId) {
        JSONObject json =  userService.arrayMenu(userId);

        return  json;
    }

    /**
     * @Method listRole
     * @Author 熊冰
     * @Version  1.0
     * @Description
     * @param lRoleId
     * @Return com.indusfo.spc.vo.JSONObject
     * @Exception 角色  权限列表
     * @Date 2019/9/2 8:58
     */
    @RequestMapping("/service/listRole")
    @ResponseBody
    public JSONObject listRole(Integer lRoleId) {
        JSONObject json =  userService.listRole(lRoleId);
        return  json;

    }
    @RequestMapping("/service/listMenu")
    @ResponseBody
    public JSONObject listMenu(Integer userId) {
        JSONObject json =  userService.listMenu(userId);
        return  json;

    }
}
